package com.zbf.auth.web;

import com.zbf.auth.denglu.MyUserServiceDetail;
import com.zbf.auth.dxapi.MsgApi;
import com.zbf.common.utils.MailQQUtils;
import com.zbf.common.utils.RanDomUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

/**
 * 作者: Mr.Wu
 * 日期: 2020/9/11
 * 描述:
 */
@RestController
@RequestMapping("telcode")
public class MySendMsg {

    @Autowired
    MsgApi msgApi;
    @Autowired
    RedisTemplate<String,String> redisTemplate;

    @RequestMapping("sg")
    public String send(String phone){
        String code = RanDomUtils.getFourRandom();
        if (MyUserServiceDetail.isPhone(phone)){
            System.out.println("用户手机号****"+phone);
            String s = msgApi.getCode(phone,code);
            redisTemplate.opsForValue().set("code",code);
            System.out.println("yzm****"+s);
            return s;
        }else {
            System.out.println("用户邮箱****"+phone);
            MailQQUtils.sendMessage(phone,code,"云翔科技","");
            redisTemplate.opsForValue().set("email",code);
            return "success";
        }

    }
}
